package com.base.cn.platform.os.controller.agent.income;

import com.base.cn.platform.os.common.AdminBaseController;
import com.base.cn.platform.os.service.course.agent.income.AgentIncomeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.math.BigDecimal;
import java.util.Map;

/**
 * @author LIZHIPENG
 * @create 2018-05-11 下午 4:15
 */
@Controller
@RequestMapping("/admin/agent/income")
public class AdminAgentIncomeController extends AdminBaseController {

    @Autowired
    private AgentIncomeService agentIncomeService;

    /**
     * 初始化收益列表页面
     * @return
     */
    @RequestMapping("/queryAgentIncomeList")
    public String queryAgentIncomeList(){
        return resultPage("/agent/income/agent-income-list");
    }

    /**
     * 查询收益列表数据
     * @param model
     * @param currentPage
     * @param params
     * @return
     */
    @RequestMapping("/ajaxQueryAgentIncomeList")
    public String ajaxQueryAgentIncomeList(Model model,
                                           @RequestParam(value = "currentPage", required = false, defaultValue = "1")int currentPage,
                                           @RequestBody Map<String,Object> params){
        Map<String, Object> dataMap = agentIncomeService.queryAgentIncomeListPage(currentPage, params, true);
        model.addAttribute("dataMap", dataMap);
        return resultPage("/agent/income/ajax-agent-income-list");
    }

    /**
     * 初始化推广员收益明细列表页
     * @param model
     * @param agentUserId
     * @return
     */
    @RequestMapping("/queryAgentIncomeInfo")
    public String queryAgentIncomeInfo(Model model,
                                       @RequestParam("agentUserId")BigDecimal agentUserId){
        Map<String, Object> agentIncome = agentIncomeService.findAgentIncomeById(agentUserId, true);
        model.addAttribute("agentIncome", agentIncome);
        return resultPage("/agent/income/agent-income-info");
    }
}
